package com.qf.config;

import com.alibaba.druid.pool.DruidDataSource;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;

import javax.sql.DataSource;

/**
 *
 * @Configuration: 此类相当于 是一个配置文件(可以完全取代 xml配置文件)
 * @author 千锋教育
 * @Company http://www.mobiletrain.org/
 * @Version 1.0
 */
//@Configuration
//@ComponentScan(basePackages = "com.qf.service")
//@PropertySource("classpath:jdbc.properties")
public class SpringConfig {

    @Value("${jdbc.driverClass}")
    private String driverClass ;
    @Value("${jdbc.url}")
    private String url;
    @Value("${jdbc.username}")
    private String username;
    @Value("${jdbc.password}")
    private String password;


    @Bean("dataSource")
    public DataSource createDataSource(){
        DruidDataSource dataSource = new DruidDataSource();
        dataSource.setDriverClassName(driverClass);
        dataSource.setUrl(url);
        dataSource.setUsername(username);
        dataSource.setPassword(password);
        return  dataSource;
    }
}
